//
//  DDSettingViewController.m
//  Dingdong
//
//  Created by 程强 on 16/11/23.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDSettingViewController.h"
#import "DDLoginManager.h"

@interface DDSettingViewController ()
@property (weak, nonatomic) IBOutlet UILabel *versionLbl;
@property (weak, nonatomic) IBOutlet UIButton *logoutBtn;
@property (strong, nonatomic) DDLoginManager *manager;
@end

@implementation DDSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.manager = [DDLoginManager new];
    [self layoutSettingView];
}
- (void)layoutSettingView
{
    self.versionLbl.text = FormatString(@"V%@", AppVersion);
    self.logoutBtn.layer.cornerRadius = 3.0;
    if ([SystemConfig shareInstance].isLogin) {
        self.logoutBtn.hidden = NO;
    }else{
        self.logoutBtn.hidden = YES;
    }
}
- (IBAction)logoutClick:(id)sender
{
    NSString *token = [SystemConfig shareInstance].token;
    [self showHUD];
    [[self.manager logout:token]subscribeNext:^(id x) {
        
        [self showMessageHUD:@"Logout success" delayHide:1.0];
        [SystemConfig shareInstance].isLogin = NO;
        [SystemConfig shareInstance].user = nil;
        [SystemConfig shareInstance].token = @"";
        [[SystemConfig shareInstance] setCartCount:0];
        [self.navigationController popViewControllerAnimated:YES];
        
    } error:^(NSError *error) {
        
    } completed:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
